package com.andova.cameraview;

import android.view.View;

import androidx.annotation.Nullable;

import java.util.List;
import java.util.Set;

abstract class CameraViewImpl implements ICameraInfo {
    protected final Callback mCallback;
    protected final PreviewImpl mPreview;

    CameraViewImpl(Callback callback, PreviewImpl preview) {
        mCallback = callback;
        mPreview = preview;
    }

    View getView() {
        return mPreview.getView();
    }

    abstract boolean start();

    abstract boolean start(boolean callbackFrameData);

    /**
     * @param callbackFrameData toggle callback nv21 frame data
     * @return {@code true} if the implementation was able to start the camera session.
     */
    abstract boolean start(boolean callbackFrameData, int frameRange);

    abstract void stop();

    abstract boolean isReady();

    abstract boolean isCameraOpened();

    abstract int getFacing();

    abstract void setFacing(int facing);

    abstract void setFacing(int facing, boolean force);

    abstract Set<AspectRatio> getSupportedAspectRatios();

    /**
     * @return {@code true} if the aspect ratio was changed.
     */
    abstract boolean setAspectRatio(AspectRatio ratio);

    abstract AspectRatio getAspectRatio();

    abstract boolean getAutoFocus();

    abstract void setAutoFocus(boolean autoFocus);

    abstract int getFlash();

    abstract void setFlash(int flash);

    abstract void lazyCallback(long millis);

    abstract void takePicture();

    abstract void setDisplayOrientation(int displayOrientation);

    abstract void toggleDrawPreview(boolean draw);

    @YUV
    abstract int getFormat();

    abstract void setFormat(@YUV int format);

    interface Callback {
        void onOpened();

        void onClosed();

        void onDisconnected();

        void onError(int error, @Nullable Throwable t);

        void onPictTaken(@Nullable byte[] data);

        void onPrevFrame(@Nullable byte[] data);

        @Nullable
        Size onPrevSize(List<Size> sizes);

        /**
         * @return 不能大于 {@link #onPrevSize(List)}
         */
        @Nullable
        Size onPictSize(List<Size> sizes);
    }
}
